package com.jrj.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;


import com.jrj.domain.User;

import com.jrj.service.LoginService;
import com.jrj.util.ConfigUtil;
import com.jrj.util.VelocityUtil;
import com.opensymphony.xwork2.ActionSupport;

/**
 *@author Adminstrator
 *@version createTime��2011-11-9 
 */
public class LoginAction extends ActionSupport {

	/**
	 * 
	 */
	
	@Autowired
	private LoginService loginService;
	
	private VelocityUtil velocityUtil;
	
	private User user;
	
	private String name;
	
	private List<User> listUser;
	
	private static final long serialVersionUID = 1L;
	
	public String login(){
		try {
			System.out.println("start");
			//User  u = loginService.getUser(user.getName());
			
			User  u = loginService.getUserByName(user.getName());
			System.out.println(u.getName());
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "login";
	}
	
	
	
	public String addUser() throws Exception{
		super.execute();
		System.out.println(name+"-----------");
		loginService.addUser(user);
		return "adduser";
	}
	
	public String user(){
		try {
			System.out.println("start");
			listUser = loginService.getUser();
			
			System.out.println("end");
		} catch (Exception e) {
			e.printStackTrace();
		}
		for (User u : listUser) {
			System.err.println(u.getName());
		}
		return "UserList";
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * VelocityUtil
	 * @param f
	 * @param min
	 * @param max
	 */
	private void publishMaxAndMinTime(String f,String min,String max) {
		String file =file = ConfigUtil.getInstance().getString("test.htmlPath")+f+ ".shtml";
		String vm = ConfigUtil.getInstance().getString("test.templatePath")+ f+ ".shtml";
		Map context = new HashMap();
		context.put("min", min);
		context.put("max", max);
		try {
			velocityUtil.mergeToFile(vm, file, context);
//			String msgurl = ConfigUtil.getInstance()
//					.getString("finance.msgurl");
//			String cacheurl = ConfigUtil.getInstance().getString(
//					"finance.cacheurl");
//			SendMessageUtil.send(file.substring(5), msgurl, cacheurl);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	public VelocityUtil getVelocityUtil() {
		return velocityUtil;
	}


	public void setVelocityUtil(VelocityUtil velocityUtil) {
		this.velocityUtil = velocityUtil;
	}
	
	
	public User getUser() {
		return user;
	}



	public void setUser(User user) {
		this.user = user;
	}
	


	public void setListUser(List<User> listUser) {
		this.listUser = listUser;
	}



	public List<User> getListUser() {
		return listUser;
	}



	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}

	

//	public static void main(String[] args) {
//		System.out.println(ConfigUtil.getInstance().getString("test.templatePath"));
//	}
	
}
